# 数据库的工具类
import mysql.connector as mysql_conn

#获取链接
def get_conn():
    try:
        conn = mysql_conn.connect(host = 'localhost',
                                  database = 'bilibili',
                                  user = 'root',
                                  password = 'dlyzwdxy0108zhj'
                                  )
        return conn
    except mysql_conn.Error:
        print("数据库连接异常")


#关闭连接
def close_conn(conn,cursor):
    try:
        if cursor:
            cursor.close()
        if conn:
            conn.close()
    except mysql_conn.Error:
        print("bye")
    finally:
        cursor.close()
        conn.close()


print(get_conn())